<?php
declare (strict_types=1);

namespace app\admin\controller;

use addons\BuilderPlus\components\Button;
use addons\BuilderPlus\components\Column as Col;
use addons\BuilderPlus\facade\Table;
use app\common\model\Assets;

class Remit extends Base
{
    public function getOptions(): array
    {
        return [
            'pk'     => 'id',
            'model'  => \app\common\model\Remit::class,
            'with'   => ['user'],
            'append' => ['statusText', 'payWayText'],
            'fast'   => [
                'edit'  => 'remit/edit',
                'save'  => '_save',
                'batch' => 'batch'
            ]
        ];
    }

    public function index(): string
    {
        return Table::init($this)
            ->addColumns([
                ['id', '记录ID', fn(Col $col) => $col->width(80)],
                ['uid', '相关会员', fn(Col $col) => $col->templet('#_userTpl')->width(250)],
                ['account', '充值账户'],
                ['amount', '充值金额'],
                ['pay_way', '支付方式', fn(Col $col) => $col->templet('{{d.payWayText}}')],
                ['images', '付款凭证', fn($col) => $col->width(80)->lazyImage()],
                ['create_time', '申请时间', fn($col) => $col->width(140)],
                ['admin_name', '审核人'],
                ['confirm_time', '审核时间', fn($col) => $col->width(140)],
                ['status', '状态', fn($col) => $col->templet('{{d.statusText}}')->fixed('right')]
            ])
            ->addTopButtons([
                'batch' => function (Button $btn) {
                    $btn->title('批量审核')
                        ->icon('layui-icon-util')
                        ->class('danger')
                        ->url(url('remit/batch')->build());
                }
            ])
            ->addRightButtons(['edit' => fn(Button $btn) => $btn
                    ->class("{{ d.status == 1 ? 'danger' : 'normal' }}")
                    ->title("{{ d.status == 1 ? '审核' : '查看' }}")]
                , 90)
            ->addSearch([
                ['create_time', '充值时间', fn($s) => $s->type('date')->dateType('datetime')],
                ['uid', '会员编号/昵称/手机号', fn($s) => $s->relation('\app\common\model\User', 'code|nickname|mobile,id')],
                ['account', '账户类型', fn($s) => $s->type('select')->optionValue(Assets::getFields(3))],
                ['status', '状态', fn($s) => $s->type('select')->optionValue([1 => '待审核', 2 => '已通过', 3 => '已驳回'])]
            ])
            ->enableExport()
            ->fetch();
    }
}
